package cn.dengta.webapp.trade.vo;

import java.io.Serializable;
import java.util.*;

import cn.dengta.common.context.I18N;
import cn.dengta.context.model.TradeI18nKey;
import cn.dengta.webapp.trade.entity.GroupVipEquity;
import cn.dengta.webapp.user.model.GroupVipRule;
import lombok.*;
import me.codeplayer.util.*;

@Setter
@Getter
public class GroupVipProductVO implements Serializable {

	/** 等級 */
	private Integer level;
	/** 群VIP图片 */
	private String icon;
	/** 群VIP 名称 */
	private String name;
	/** 是否可选 */
	private Boolean optional;
	/** 标题 */
	private String title;
	/** 群VIP 配置 */
	private List<GroupVipProductVO.GroupVipInfoVO> infos;

	public void ofInfoVO(GroupVipRule rule, List<GroupVipEquity.ExtendGroupVipVO> list, boolean check, Locale locale) {
		Map<String, String> map = Collections.emptyMap();
		if (X.isValid(list)) {
			map = CollectionUtil.toHashMap(list, GroupVipEquity.ExtendGroupVipVO::getName, GroupVipEquity.ExtendGroupVipVO::getIcon);
		}
		List<GroupVipProductVO.GroupVipInfoVO> vos = new ArrayList<>();
		if (Cmp.gt(rule.getGroupAdmin(), 0)) {
			vos.add(new GroupVipProductVO.GroupVipInfoVO(map.get(GroupVipRule.GROUP_ADMIN), I18N.msg(TradeI18nKey.USER_GROUP_VIP_PANEL_MANAGER, locale, rule.getGroupAdmin())));
		}

		if (Cmp.gt(rule.getGroupMember(), 0)) {
			vos.add(new GroupVipProductVO.GroupVipInfoVO(map.get(GroupVipRule.GROUP_MEMBER), I18N.msg(TradeI18nKey.USER_GROUP_VIP_PANEL_MEMBER, locale, rule.getGroupMember())));
		}

		if (Cmp.gt(rule.getGroupNumber(), 0)) {
			vos.add(new GroupVipProductVO.GroupVipInfoVO(map.get(GroupVipRule.GROUP_NUMBER), I18N.msg(TradeI18nKey.USER_GROUP_VIP_PANEL_NUMBER, locale, rule.getGroupNumber())));
		}

		if (!check && Cmp.gt(rule.getPrivateChatNumber(), 0)) {
			vos.add(new GroupVipProductVO.GroupVipInfoVO(map.get(GroupVipRule.PRIVATE_CHAT_NUMBER), I18N.msg(TradeI18nKey.USER_GROUP_VIP_PANEL_CHAT, locale, rule.getPrivateChatNumber())));
		}
		this.infos = vos;
	}

	@Setter
	@Getter
	@AllArgsConstructor
	public static class GroupVipInfoVO {

		/** 权益图片 */
		private String icon;
		/** 权益信息 */
		private String info;

	}

}
